package com.ruoyi.web.controller.mes;


import com.kt.mes.opc.OpcClientUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mes/opc")
public class OpcController  extends BaseController {


    @GetMapping("/one")
    public AjaxResult one(String opcUrl,String opcName,String opcPwd)
    {

        System.out.println("测试 OPC 连接");
        System.out.println(opcUrl);
        System.out.println(opcName);
        System.out.println(opcPwd);


        try {

//            OpcUaClient opc= OpcClientUtil.createClient("opc.tcp://"+opcUrl,opcName,opcPwd);
//
//            opc.connect().get();
//            NodeId node= NodeId.parse("ns=3;s=\"TOMES\".\"工位1上电状态\"");
//            UaVariableNode ua=  opc.getAddressSpace().getVariableNode(node);
//            System.out.println(ua.getValue());


        }catch (Exception e){

            System.out.println(e);
            return AjaxResult.error("OPC连接失败！");
        }

        return AjaxResult.success("OPC连接成功！");
    }

}
